home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / IO / BufferedInputStream.class (.txt) next >
Encoding:
Java Class File  |  1997-04-14  |  1.5 KB  |  107 lines

  1. package java.io;
  2.  
  3. public class BufferedInputStream extends FilterInputStream {
  4.    protected byte[] buf;
  5.    protected int count;
  6.    protected int pos;
  7.    protected int markpos;
  8.    protected int marklimit;
  9.  
  10.    public BufferedInputStream(InputStream var1) {
  11.       this(var1, 2048);
  12.    }
  13.  
  14.    public BufferedInputStream(InputStream var1, int var2) {
  15.       super(var1);
  16.       this.markpos = -1;
  17.       this.buf = new byte[var2];
  18.    }
  19.  
  20.    private void fill() throws IOException {
  21.       if (this.markpos < 0) {
  22.          this.pos = 0;
  23.       } else if (this.pos >= this.buf.length) {
  24.          if (this.markpos > 0) {
  25.             int var1 = this.pos - this.markpos;
  26.             System.arraycopy(this.buf, this.markpos, this.buf, 0, var1);
  27.             this.pos = var1;
  28.             this.markpos = 0;
  29.          } else if (this.buf.length >= this.marklimit) {
  30.             this.markpos = -1;
  31.             this.pos = 0;
  32.          } else {
  33.             int var3 = this.pos * 2;
  34.             if (var3 > this.marklimit) {
  35.                var3 = this.marklimit;
  36.             }
  37.  
  38.             byte[] var2 = new byte[var3];
  39.             System.arraycopy(this.buf, 0, var2, 0, this.pos);
  40.             this.buf = var2;
  41.          }
  42.       }
  43.  
  44.       int var4 = super.in.read(this.buf, this.pos, this.buf.length - this.pos);
  45.       this.count = var4 <= 0 ? 0 : var4 + this.pos;
  46.    }
  47.  
  48.    public synchronized int read() throws IOException {
  49.       if (this.pos >= this.count) {
  50.          this.fill();
  51.          if (this.count == 0) {
  52.             return -1;
  53.          }
  54.       }
  55.  
  56.       return this.buf[this.pos++] & 255;
  57.    }
  58.  
  59.    public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
  60.       int var4 = this.count - this.pos;
  61.       if (var4 <= 0) {
  62.          this.fill();
  63.          var4 = this.count - this.pos;
  64.          if (var4 <= 0) {
  65.             return -1;
  66.          }
  67.       }
  68.  
  69.       int var5 = var4 < var3 ? var4 : var3;
  70.       System.arraycopy(this.buf, this.pos, var1, var2, var5);
  71.       this.pos += var5;
  72.       return var5;
  73.    }
  74.  
  75.    public synchronized long skip(long var1) throws IOException {
  76.       long var3 = (long)(this.count - this.pos);
  77.       if (var3 >= var1) {
  78.          this.pos = (int)((long)this.pos + var1);
  79.          return var1;
  80.       } else {
  81.          this.pos = (int)((long)this.pos + var3);
  82.          return var3 + super.in.skip(var1 - var3);
  83.       }
  84.    }
  85.  
  86.    public synchronized int available() throws IOException {
  87.       return this.count - this.pos + super.in.available();
  88.    }
  89.  
  90.    public synchronized void mark(int var1) {
  91.       this.marklimit = var1;
  92.       this.markpos = this.pos;
  93.    }
  94.  
  95.    public synchronized void reset() throws IOException {
  96.       if (this.markpos < 0) {
  97.          throw new IOException("Resetting to invalid mark");
  98.       } else {
  99.          this.pos = this.markpos;
  100.       }
  101.    }
  102.  
  103.    public boolean markSupported() {
  104.       return true;
  105.    }
  106. }
  107.